<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" integrity="sha256-dABdfBfUoC8vJUBOwGVdm8L9qlMWaHTIfXt+7GnZCIo=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/black/pace-theme-flat-top.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous" defer></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"tryhub.top","root":"/","images":"/images","scheme":"Gemini","darkmode":true,"version":"8.23.0","exturl":false,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":true,"copycode":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"bookmark":{"enable":true,"color":"#222","save":"manual"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"duration":200,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.json","localsearch":{"enable":true,"top_n_per_article":1,"unescape":true,"preload":true,"trigger":"auto"}}</script><script src="/js/config.js" defer></script>

    <meta name="description" content="什么是 MyBatis ？MyBatis 是一款优秀的持久层框架，它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息，将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。 MyBatis的">
<meta property="og:type" content="article">
<meta property="og:title" content="MyBatis 映射配置解析以及动态SQL配置案例">
<meta property="og:url" content="https://tryhub.top/2018/04/05/MyBatis-%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE%E8%A7%A3%E6%9E%90%E4%BB%A5%E5%8F%8A%E5%8A%A8%E6%80%81SQL%E9%85%8D%E7%BD%AE%E6%A1%88%E4%BE%8B/index.html">
<meta property="og:site_name" content="奇姆的博客">
<meta property="og:description" content="什么是 MyBatis ？MyBatis 是一款优秀的持久层框架，它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息，将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。 MyBatis的">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2018-04-05T13:21:59.000Z">
<meta property="article:modified_time" content="2023-07-07T07:27:11.746Z">
<meta property="article:author" content="Jaron Chim">
<meta property="article:tag" content="idea">
<meta property="article:tag" content="mysql">
<meta property="article:tag" content="多对多">
<meta property="article:tag" content="一对多">
<meta property="article:tag" content="多对一">
<meta property="article:tag" content="mybatis">
<meta property="article:tag" content="一对一">
<meta property="article:tag" content="动态SQL">
<meta property="article:tag" content="映射配置">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://tryhub.top/2018/04/05/MyBatis-%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE%E8%A7%A3%E6%9E%90%E4%BB%A5%E5%8F%8A%E5%8A%A8%E6%80%81SQL%E9%85%8D%E7%BD%AE%E6%A1%88%E4%BE%8B/">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://tryhub.top/2018/04/05/MyBatis-%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE%E8%A7%A3%E6%9E%90%E4%BB%A5%E5%8F%8A%E5%8A%A8%E6%80%81SQL%E9%85%8D%E7%BD%AE%E6%A1%88%E4%BE%8B/","path":"2018/04/05/MyBatis-映射配置解析以及动态SQL配置案例/","title":"MyBatis 映射配置解析以及动态SQL配置案例"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>MyBatis 映射配置解析以及动态SQL配置案例 | 奇姆的博客</title>
  

  <script src="/js/third-party/analytics/baidu-analytics.js" defer></script>
  <script async src="https://hm.baidu.com/hm.js?1ad13b7aff8bfe9206fa7e12d5c4a4f0"></script>







  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous" defer></script>
<script src="/js/utils.js" defer></script><script src="/js/motion.js" defer></script><script src="/js/sidebar.js" defer></script><script src="/js/next-boot.js" defer></script><script src="/js/bookmark.js" defer></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous" defer></script>
<script src="/js/third-party/search/local-search.js" defer></script>





  <script src="/js/third-party/pace.js" defer></script>


  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="奇姆的博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">奇姆的博客</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF-MyBatis-%EF%BC%9F"><span class="nav-number">1.</span> <span class="nav-text">什么是 MyBatis ？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MyBatis%E7%9A%84-Git-%E4%BB%A3%E7%A0%81%E5%BA%93"><span class="nav-number">2.</span> <span class="nav-text">MyBatis的 Git 代码库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#corp%E6%95%B0%E6%8D%AE%E5%BA%93%E5%85%A8%E9%83%A8%E8%A1%A8%E7%BB%93%E6%9E%84%E4%B8%8E%E6%95%B0%E6%8D%AE"><span class="nav-number">3.</span> <span class="nav-text">corp数据库全部表结构与数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#pom-xml"><span class="nav-number">4.</span> <span class="nav-text">pom.xml</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MybatisUtil-Mybatis%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="nav-number">5.</span> <span class="nav-text">MybatisUtil Mybatis工具类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Depa-%E9%83%A8%E9%97%A8%E5%AE%9E%E4%BD%93%E7%B1%BB"><span class="nav-number">6.</span> <span class="nav-text">Depa 部门实体类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AF%B9%E5%BA%94-Depa-%E9%83%A8%E9%97%A8%E5%AE%9E%E4%BD%93%E7%B1%BB-%E7%9A%84%E5%AE%9E%E7%8E%B0%E6%8E%A5%E5%8F%A3-DepaDao-%E6%8E%A5%E5%8F%A3%E7%B1%BB"><span class="nav-number">7.</span> <span class="nav-text">对应 Depa 部门实体类 的实现接口 DepaDao 接口类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AF%B9%E5%BA%94-Depa-%E9%83%A8%E9%97%A8%E5%AE%9E%E4%BD%93%E7%B1%BB-%E7%9A%84%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-DepaMapper-xml"><span class="nav-number">8.</span> <span class="nav-text">对应 Depa 部门实体类 的映射配置文件 DepaMapper.xml</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Emp-%E8%81%8C%E5%91%98%E5%AE%9E%E4%BD%93%E7%B1%BB"><span class="nav-number">9.</span> <span class="nav-text">Emp 职员实体类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AF%B9%E5%BA%94-Emp-%E8%81%8C%E5%91%98%E5%AE%9E%E4%BD%93%E7%B1%BB-%E7%9A%84%E5%AE%9E%E7%8E%B0%E6%8E%A5%E5%8F%A3-EmpDao-%E6%8E%A5%E5%8F%A3%E7%B1%BB"><span class="nav-number">10.</span> <span class="nav-text">对应 Emp 职员实体类 的实现接口 EmpDao 接口类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AF%B9%E5%BA%94-Emp-%E8%81%8C%E5%91%98%E5%AE%9E%E4%BD%93%E7%B1%BB-%E7%9A%84%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-EmpMapper-xml"><span class="nav-number">11.</span> <span class="nav-text">对应 Emp 职员实体类 的映射配置文件 EmpMapper.xml</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Post-%E8%81%8C%E4%BD%8D%E5%AE%9E%E4%BD%93%E7%B1%BB"><span class="nav-number">12.</span> <span class="nav-text">Post 职位实体类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AF%B9%E5%BA%94-Post-%E8%81%8C%E4%BD%8D%E5%AE%9E%E4%BD%93%E7%B1%BB-%E7%9A%84%E5%AE%9E%E7%8E%B0%E6%8E%A5%E5%8F%A3-PostDao-%E6%8E%A5%E5%8F%A3%E7%B1%BB"><span class="nav-number">13.</span> <span class="nav-text">对应 Post 职位实体类 的实现接口 PostDao 接口类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AF%B9%E5%BA%94-Post-%E8%81%8C%E4%BD%8D%E5%AE%9E%E4%BD%93%E7%B1%BB-%E7%9A%84%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-PostMapper-xml"><span class="nav-number">14.</span> <span class="nav-text">对应 Post 职位实体类 的映射配置文件 PostMapper.xml</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#mybatis-config-xml-MyBatis%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-number">15.</span> <span class="nav-text">mybatis-config.xml MyBatis配置文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Test-%E6%B5%8B%E8%AF%95%E7%B1%BB"><span class="nav-number">16.</span> <span class="nav-text">Test 测试类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8E%A7%E5%88%B6%E5%8F%B0%E8%BE%93%E5%87%BA%E7%BB%93%E6%9E%9C"><span class="nav-number">17.</span> <span class="nav-text">控制台输出结果</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Jaron Chim"
      src="/images/jaron.gif">
  <p class="site-author-name" itemprop="name">Jaron Chim</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">76</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">95</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">144</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/admin-Jaron" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;admin-Jaron" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:tryhub@tryhub.top" title="E-Mail → mailto:tryhub@tryhub.top" rel="noopener me"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>

        </div>
      </div>
        <div class="back-to-top animated" role="button" aria-label="返回顶部">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://tryhub.top/2018/04/05/MyBatis-%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE%E8%A7%A3%E6%9E%90%E4%BB%A5%E5%8F%8A%E5%8A%A8%E6%80%81SQL%E9%85%8D%E7%BD%AE%E6%A1%88%E4%BE%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/jaron.gif">
      <meta itemprop="name" content="Jaron Chim">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="奇姆的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="MyBatis 映射配置解析以及动态SQL配置案例 | 奇姆的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          MyBatis 映射配置解析以及动态SQL配置案例
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2018-04-05 21:21:59" itemprop="dateCreated datePublished" datetime="2018-04-05T21:21:59+08:00">2018-04-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-07-07 15:27:11" itemprop="dateModified" datetime="2023-07-07T15:27:11+08:00">2023-07-07</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/mybatis/" itemprop="url" rel="index"><span itemprop="name">mybatis</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/mybatis/xml/" itemprop="url" rel="index"><span itemprop="name">xml</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/mybatis/xml/%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE/" itemprop="url" rel="index"><span itemprop="name">映射配置</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/mybatis/xml/%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE/%E5%8A%A8%E6%80%81SQL/" itemprop="url" rel="index"><span itemprop="name">动态SQL</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><h2 id="什么是-MyBatis-？"><a href="#什么是-MyBatis-？" class="headerlink" title="什么是 MyBatis ？"></a>什么是 MyBatis ？</h2><p>MyBatis 是一款优秀的持久层框架，它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息，将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。</p>
<h2 id="MyBatis的-Git-代码库"><a href="#MyBatis的-Git-代码库" class="headerlink" title="MyBatis的 Git 代码库"></a><a target="_blank" rel="noopener" href="https://github.com/mybatis/mybatis-3/tree/master/src/site">MyBatis的 Git 代码库</a></h2><span id="more"></span>

<h2 id="corp数据库全部表结构与数据"><a href="#corp数据库全部表结构与数据" class="headerlink" title="corp数据库全部表结构与数据"></a>corp数据库全部表结构与数据</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> DATABASE IF <span class="keyword">EXISTS</span> `corp`;</span><br><span class="line"></span><br><span class="line"><span class="keyword">CREATE</span> DATABASE `corp`;</span><br><span class="line"></span><br><span class="line">USE `corp`;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 部门</span></span><br><span class="line"> <span class="keyword">CREATE TABLE</span> `depa` (</span><br><span class="line">  `id` <span class="type">INT</span> AUTO_INCREMENT <span class="keyword">PRIMARY KEY</span>,</span><br><span class="line">  `depa_name` NVARCHAR (<span class="number">50</span>) <span class="keyword">NOT NULL</span></span><br><span class="line">) ;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 职员</span></span><br><span class="line"> <span class="keyword">CREATE TABLE</span> `emp` (</span><br><span class="line">  `id` <span class="type">INT</span> AUTO_INCREMENT <span class="keyword">PRIMARY KEY</span>,</span><br><span class="line">  `emp_name` NVARCHAR (<span class="number">50</span>) <span class="keyword">NOT NULL</span>,</span><br><span class="line">  `depa_id` <span class="type">INT</span> <span class="keyword">NOT NULL</span></span><br><span class="line">) ;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 职位</span></span><br><span class="line"> <span class="keyword">CREATE TABLE</span> `post` (</span><br><span class="line">  `id` <span class="type">INT</span> AUTO_INCREMENT <span class="keyword">PRIMARY KEY</span>,</span><br><span class="line">  `post_name` NVARCHAR (<span class="number">50</span>) <span class="keyword">NOT NULL</span></span><br><span class="line">) ;</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 职员职位</span></span><br><span class="line"> <span class="keyword">CREATE TABLE</span> `emp_post` (</span><br><span class="line">  `emp_id` <span class="type">INT</span> <span class="keyword">NOT NULL</span>,</span><br><span class="line">  `post_id` <span class="type">INT</span> <span class="keyword">NOT NULL</span></span><br><span class="line">) ;</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT INTO</span> `depa`(`depa_name`) <span class="keyword">VALUES</span>(<span class="string">&#x27;销售部&#x27;</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `depa`(`depa_name`) <span class="keyword">VALUES</span>(<span class="string">&#x27;美工部&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp`(`emp_name`,`depa_id`) <span class="keyword">VALUES</span>(<span class="string">&#x27;张三&#x27;</span>,<span class="number">2</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp`(`emp_name`,`depa_id`) <span class="keyword">VALUES</span>(<span class="string">&#x27;李四&#x27;</span>,<span class="number">1</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp`(`emp_name`,`depa_id`) <span class="keyword">VALUES</span>(<span class="string">&#x27;王五&#x27;</span>,<span class="number">1</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp`(`emp_name`,`depa_id`) <span class="keyword">VALUES</span>(<span class="string">&#x27;赵六&#x27;</span>,<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT INTO</span> `post`(`post_name`) <span class="keyword">VALUES</span>(<span class="string">&#x27;职员&#x27;</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `post`(`post_name`) <span class="keyword">VALUES</span>(<span class="string">&#x27;主管&#x27;</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `post`(`post_name`) <span class="keyword">VALUES</span>(<span class="string">&#x27;经理&#x27;</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `post`(`post_name`) <span class="keyword">VALUES</span>(<span class="string">&#x27;部门经理&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp_post`(`emp_id`,`post_id`) <span class="keyword">VALUES</span>(<span class="number">1</span>,<span class="number">1</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp_post`(`emp_id`,`post_id`) <span class="keyword">VALUES</span>(<span class="number">2</span>,<span class="number">2</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp_post`(`emp_id`,`post_id`) <span class="keyword">VALUES</span>(<span class="number">3</span>,<span class="number">3</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp_post`(`emp_id`,`post_id`) <span class="keyword">VALUES</span>(<span class="number">4</span>,<span class="number">4</span>);</span><br><span class="line"><span class="keyword">INSERT INTO</span> `emp_post`(`emp_id`,`post_id`) <span class="keyword">VALUES</span>(<span class="number">1</span>,<span class="number">4</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> `depa`;</span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> `emp`;</span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> `post`;</span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> `emp_post`;</span><br><span class="line"></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> `depa`;</span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> `emp`;</span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> `post`;</span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> `emp_post`;</span><br></pre></td></tr></table></figure>

<h2 id="pom-xml"><a href="#pom-xml" class="headerlink" title="pom.xml"></a>pom.xml</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span></span></span><br><span class="line"><span class="tag">         <span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span></span><br><span class="line"><span class="tag">         <span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">modelVersion</span>&gt;</span>4.0.0<span class="tag">&lt;/<span class="name">modelVersion</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>Corp<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0-SNAPSHOT<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.mybatis<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.4.1<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>mysql<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mysql-connector-java<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>5.1.38<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">project</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="MybatisUtil-Mybatis工具类"><a href="#MybatisUtil-Mybatis工具类" class="headerlink" title="MybatisUtil Mybatis工具类"></a>MybatisUtil Mybatis工具类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.util;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.io.Resources;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.session.SqlSession;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.session.SqlSessionFactory;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.session.SqlSessionFactoryBuilder;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.io.InputStream;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MybatisUtil</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> SqlSessionFactory sessionFactory;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">static</span> &#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="type">InputStream</span> <span class="variable">inputStream</span> <span class="operator">=</span> Resources.getResourceAsStream(<span class="string">&quot;mybatis-config.xml&quot;</span>);</span><br><span class="line">            sessionFactory = <span class="keyword">new</span> <span class="title class_">SqlSessionFactoryBuilder</span>().build(inputStream);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> SqlSession <span class="title function_">getSession</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> sessionFactory.openSession(<span class="literal">false</span>);<span class="comment">//true为自动提交事务</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Depa-部门实体类"><a href="#Depa-部门实体类" class="headerlink" title="Depa 部门实体类"></a>Depa 部门实体类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.entity;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Depa</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String depa_name;</span><br><span class="line">    <span class="keyword">private</span> List&lt;Emp&gt; emps = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;Emp&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">toString</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;Depa&#123;&quot;</span> +</span><br><span class="line">                <span class="string">&quot;id=&quot;</span> + id +</span><br><span class="line">                <span class="string">&quot;, depa_name=&#x27;&quot;</span> + depa_name + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, emps=&quot;</span> + emps +</span><br><span class="line">                <span class="string">&#x27;&#125;&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> Integer <span class="title function_">getId</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setId</span><span class="params">(Integer id)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.id = id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getDepa_name</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> depa_name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setDepa_name</span><span class="params">(String depa_name)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.depa_name = depa_name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> List&lt;Emp&gt; <span class="title function_">getEmps</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> emps;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setEmps</span><span class="params">(List&lt;Emp&gt; emps)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.emps = emps;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="对应-Depa-部门实体类-的实现接口-DepaDao-接口类"><a href="#对应-Depa-部门实体类-的实现接口-DepaDao-接口类" class="headerlink" title="对应 Depa 部门实体类 的实现接口 DepaDao 接口类"></a>对应 Depa 部门实体类 的实现接口 DepaDao 接口类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.dao;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.entity.Depa;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">DepaDao</span> &#123;</span><br><span class="line">    List&lt;Depa&gt; <span class="title function_">getAll</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="对应-Depa-部门实体类-的映射配置文件-DepaMapper-xml"><a href="#对应-Depa-部门实体类-的映射配置文件-DepaMapper-xml" class="headerlink" title="对应 Depa 部门实体类 的映射配置文件 DepaMapper.xml"></a>对应 Depa 部门实体类 的映射配置文件 DepaMapper.xml</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">mapper</span></span></span><br><span class="line"><span class="meta">        <span class="keyword">PUBLIC</span> <span class="string">&quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;</span></span></span><br><span class="line"><span class="meta">        <span class="string">&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!--namespace mapper接口 必填 随便填值 防止SQL语句ID重名--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">&quot;com.dao.DepaDao&quot;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--&lt;insert id=&quot;&quot;&gt;&lt;/insert&gt;--&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--&lt;delete id=&quot;&quot;&gt;&lt;/delete&gt;--&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--&lt;update id=&quot;&quot;&gt;&lt;/update&gt;--&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--resultType 返回类型 实体类全限定类名--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">&quot;getAll&quot;</span> <span class="attr">resultMap</span>=<span class="string">&quot;DepaMapper&quot;</span>&gt;</span></span><br><span class="line">        SELECT *,e.`id` eId,d.`id` dId FROM depa d</span><br><span class="line">        INNER JOIN emp e ON d.`id`=e.`depa_id`</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--type 为resultMap返回类型--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">id</span>=<span class="string">&quot;DepaMapper&quot;</span> <span class="attr">type</span>=<span class="string">&quot;Depa&quot;</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--column 为数据库查到后取的别名 property 为type对象对应属性名--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;dId&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">&lt;!--因为数据库的字段与实体类属性名一致--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--所以在 mybatis-config.xml 配置 &lt;setting name=&quot;autoMappingBehavior&quot; value=&quot;FULL&quot;/&gt;--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--达到 自动映射行为 : 局部的PARTIAL 重复的 &lt;result/&gt; 可以省略--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--&lt;result column=&quot;&quot; property=&quot;&quot;/&gt;--&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">&lt;!--收集 一对多--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--property 为type对象对应属性名 javaType 为所属类型--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">&quot;emps&quot;</span> <span class="attr">javaType</span>=<span class="string">&quot;Emp&quot;</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--column 为数据库查到后取的别名 property 为javaType对象对应属性名--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;&quot;</span> <span class="attr">property</span>=<span class="string">&quot;&quot;</span>/&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--因为数据库的字段与实体类属性名一致--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--所以在 mybatis-config.xml 配置 &lt;setting name=&quot;autoMappingBehavior&quot; value=&quot;FULL&quot;/&gt;--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--达到 自动映射行为 : 全部FULL 重复的 &lt;result/&gt; 可以省略--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;eId&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="Emp-职员实体类"><a href="#Emp-职员实体类" class="headerlink" title="Emp 职员实体类"></a>Emp 职员实体类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.entity;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Emp</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String emp_name;</span><br><span class="line">    <span class="keyword">private</span> Depa depa_id;</span><br><span class="line">    <span class="keyword">private</span> List&lt;Post&gt; posts = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;Post&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">toString</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;Emp&#123;&quot;</span> +</span><br><span class="line">                <span class="string">&quot;id=&quot;</span> + id +</span><br><span class="line">                <span class="string">&quot;, emp_name=&#x27;&quot;</span> + emp_name + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, depa_id=&quot;</span> + depa_id +</span><br><span class="line">                <span class="string">&quot;, posts=&quot;</span> + posts +</span><br><span class="line">                <span class="string">&#x27;&#125;&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> Integer <span class="title function_">getId</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setId</span><span class="params">(Integer id)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.id = id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getEmp_name</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> emp_name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setEmp_name</span><span class="params">(String emp_name)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.emp_name = emp_name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> Depa <span class="title function_">getDepa_id</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> depa_id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setDepa_id</span><span class="params">(Depa depa_id)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.depa_id = depa_id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> List&lt;Post&gt; <span class="title function_">getPosts</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> posts;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setPosts</span><span class="params">(List&lt;Post&gt; posts)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.posts = posts;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="对应-Emp-职员实体类-的实现接口-EmpDao-接口类"><a href="#对应-Emp-职员实体类-的实现接口-EmpDao-接口类" class="headerlink" title="对应 Emp 职员实体类 的实现接口 EmpDao 接口类"></a>对应 Emp 职员实体类 的实现接口 EmpDao 接口类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.dao;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.entity.Emp;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">EmpDao</span> &#123;</span><br><span class="line">    List&lt;Emp&gt; <span class="title function_">getAll</span><span class="params">()</span>;</span><br><span class="line"></span><br><span class="line">    Integer <span class="title function_">saveOrUpdate</span><span class="params">(Emp emp)</span>;</span><br><span class="line"></span><br><span class="line">    Integer <span class="title function_">del</span><span class="params">(Integer[] idArray)</span>;</span><br><span class="line"></span><br><span class="line">    List&lt;Emp&gt; <span class="title function_">getByNames</span><span class="params">(List names)</span>;</span><br><span class="line"></span><br><span class="line">    List&lt;Emp&gt; <span class="title function_">getByIdAndNames</span><span class="params">(Map map)</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="对应-Emp-职员实体类-的映射配置文件-EmpMapper-xml"><a href="#对应-Emp-职员实体类-的映射配置文件-EmpMapper-xml" class="headerlink" title="对应 Emp 职员实体类 的映射配置文件 EmpMapper.xml"></a>对应 Emp 职员实体类 的映射配置文件 EmpMapper.xml</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">mapper</span></span></span><br><span class="line"><span class="meta">        <span class="keyword">PUBLIC</span> <span class="string">&quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;</span></span></span><br><span class="line"><span class="meta">        <span class="string">&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!--namespace mapper接口 必填 随便填值 防止SQL语句ID重名--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">&quot;com.dao.EmpDao&quot;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">        &lt;where&gt; 自动删除第一个 and 或者 or</span></span><br><span class="line"><span class="comment">        item 表示集合中每一个元素进行迭代时的别名</span></span><br><span class="line"><span class="comment">        open 表示该语句以什么开始</span></span><br><span class="line"><span class="comment">        separator 表示在每次进行迭代之间以什么符号作为分隔符</span></span><br><span class="line"><span class="comment">        close表示以什么结束</span></span><br><span class="line"><span class="comment">        如果传入的是单参数且参数类型是一个List的时候，collection属性值为list</span></span><br><span class="line"><span class="comment">        如果传入的是单参数且参数类型是一个array数组的时候，collection的属性值为array</span></span><br><span class="line"><span class="comment">        如果传入的参数是多个的时候，就需要把它们封装成一个Map map的key就是参数名--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">delete</span> <span class="attr">id</span>=<span class="string">&quot;del&quot;</span>&gt;</span></span><br><span class="line">        DELETE FROM emp</span><br><span class="line">        <span class="tag">&lt;<span class="name">where</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">foreach</span> <span class="attr">collection</span>=<span class="string">&quot;array&quot;</span> <span class="attr">item</span>=<span class="string">&quot;eId&quot;</span>&gt;</span></span><br><span class="line">                OR id = #&#123;eId&#125;</span><br><span class="line">            <span class="tag">&lt;/<span class="name">foreach</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">where</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">delete</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--&lt;set&gt; 自动去除最后的逗号 , --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">update</span> <span class="attr">id</span>=<span class="string">&quot;saveOrUpdate&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">&quot;null != id&quot;</span>&gt;</span></span><br><span class="line">            UPDATE emp</span><br><span class="line">            <span class="tag">&lt;<span class="name">set</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">&quot;null != emp_name&quot;</span>&gt;</span></span><br><span class="line">                    emp_name = #&#123;emp_name&#125;,</span><br><span class="line">                <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">&quot;null != depa_id and null != depa_id.id&quot;</span>&gt;</span></span><br><span class="line">                    depa_id = #&#123;depa_id.id&#125;,</span><br><span class="line">                <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">set</span>&gt;</span></span><br><span class="line">            where id = #&#123;id&#125;</span><br><span class="line">        <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">&quot;null == id&quot;</span>&gt;</span></span><br><span class="line">            INSERT INTO `emp`(`emp_name`,`depa_id`) VALUES(#&#123;emp_name&#125;,#&#123;depa_id.id&#125;)</span><br><span class="line">        <span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">update</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--resultType 返回类型 实体类全限定类名--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">&quot;getAll&quot;</span> <span class="attr">resultMap</span>=<span class="string">&quot;EmpMapper&quot;</span>&gt;</span></span><br><span class="line">        SELECT * FROM emp e</span><br><span class="line">        INNER JOIN depa d ON d.`id`=e.`depa_id`</span><br><span class="line">        INNER JOIN emp_post ep ON ep.`emp_id`=e.`id`</span><br><span class="line">        INNER JOIN post p ON p.`id`=ep.`post_id`</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">        prefix 前缀添加什么</span></span><br><span class="line"><span class="comment">        prefixOverrides 前缀移除什么 || 为或者</span></span><br><span class="line"><span class="comment">        suffix 后缀添加什么</span></span><br><span class="line"><span class="comment">        suffixOverrides 后缀移除什么 || 为或者</span></span><br><span class="line"><span class="comment">        &lt;trim prefix=&quot;WHERE&quot; prefixOverrides=&quot;OR || AND&quot;&gt; 等价 &lt;where&gt;--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">&quot;getByNames&quot;</span> <span class="attr">resultMap</span>=<span class="string">&quot;EmpMapper&quot;</span>&gt;</span></span><br><span class="line">        SELECT * FROM emp e</span><br><span class="line">        INNER JOIN depa d ON d.`id`=e.`depa_id`</span><br><span class="line">        INNER JOIN emp_post ep ON ep.`emp_id`=e.`id`</span><br><span class="line">        INNER JOIN post p ON p.`id`=ep.`post_id`</span><br><span class="line">        <span class="tag">&lt;<span class="name">trim</span> <span class="attr">prefix</span>=<span class="string">&quot;WHERE&quot;</span> <span class="attr">prefixOverrides</span>=<span class="string">&quot;OR || AND&quot;</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">foreach</span> <span class="attr">collection</span>=<span class="string">&quot;list&quot;</span> <span class="attr">item</span>=<span class="string">&quot;name&quot;</span>&gt;</span></span><br><span class="line">                OR e.`emp_name` LIKE CONCAT(&#x27;%&#x27;,#&#123;name&#125;,&#x27;%&#x27;)</span><br><span class="line">            <span class="tag">&lt;/<span class="name">foreach</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">trim</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">    prefix 前缀添加什么</span></span><br><span class="line"><span class="comment">    prefixOverrides 前缀移除什么 || 为或者</span></span><br><span class="line"><span class="comment">    suffix 后缀添加什么</span></span><br><span class="line"><span class="comment">    suffixOverrides 后缀移除什么 || 为或者</span></span><br><span class="line"><span class="comment">    &lt;trim prefix=&quot;WHERE&quot; prefixOverrides=&quot;OR || AND&quot;&gt; 等价 &lt;where&gt;--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">&quot;getByIdAndNames&quot;</span> <span class="attr">resultMap</span>=<span class="string">&quot;EmpMapper&quot;</span>&gt;</span></span><br><span class="line">        SELECT * FROM emp e</span><br><span class="line">        INNER JOIN depa d ON d.`id`=e.`depa_id`</span><br><span class="line">        INNER JOIN emp_post ep ON ep.`emp_id`=e.`id`</span><br><span class="line">        INNER JOIN post p ON p.`id`=ep.`post_id`</span><br><span class="line">        <span class="tag">&lt;<span class="name">trim</span> <span class="attr">prefix</span>=<span class="string">&quot;WHERE&quot;</span> <span class="attr">prefixOverrides</span>=<span class="string">&quot;OR|AND&quot;</span>&gt;</span></span><br><span class="line">            AND e.`id` = #&#123;mapIdName&#125; AND</span><br><span class="line">        <span class="tag">&lt;/<span class="name">trim</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">trim</span> <span class="attr">prefixOverrides</span>=<span class="string">&quot;OR|AND&quot;</span>&gt;</span></span><br><span class="line">            e.`emp_name` IN</span><br><span class="line">            <span class="tag">&lt;<span class="name">foreach</span> <span class="attr">collection</span>=<span class="string">&quot;mapNameList&quot;</span> <span class="attr">item</span>=<span class="string">&quot;name&quot;</span> <span class="attr">open</span>=<span class="string">&quot;(&quot;</span> <span class="attr">separator</span>=<span class="string">&quot;,&quot;</span> <span class="attr">close</span>=<span class="string">&quot;)&quot;</span>&gt;</span></span><br><span class="line">                #&#123;name&#125;</span><br><span class="line">            <span class="tag">&lt;/<span class="name">foreach</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">trim</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--type 为resultMap返回类型--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">id</span>=<span class="string">&quot;EmpMapper&quot;</span> <span class="attr">type</span>=<span class="string">&quot;Emp&quot;</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--column 为数据库查到后取的别名 property 为type对象对应属性名--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;emp_id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">&lt;!--因为数据库的字段与实体类属性名一致--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--所以在 mybatis-config.xml 配置 &lt;setting name=&quot;autoMappingBehavior&quot; value=&quot;FULL&quot;/&gt;--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--达到 自动映射行为 : 局部的PARTIAL 重复的 &lt;result/&gt; 可以省略--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--&lt;result column=&quot;&quot; property=&quot;&quot;/&gt;--&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">&lt;!--联合查询 一对一--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--property 为type对象对应属性名 javaType 为所属类型--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">&quot;depa_id&quot;</span> <span class="attr">javaType</span>=<span class="string">&quot;Depa&quot;</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--column 为数据库查到后取的别名 property 为javaType对象对应属性名--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;depa_id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--因为数据库的字段与实体类属性名一致--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--所以在 mybatis-config.xml 配置 &lt;setting name=&quot;autoMappingBehavior&quot; value=&quot;FULL&quot;/&gt;--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--达到 自动映射行为 : 全部FULL 重复的 &lt;result/&gt; 可以省略--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--&lt;result column=&quot;&quot; property=&quot;&quot;/&gt;--&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">association</span>&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">&lt;!--收集 一对多--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--property 为type对象对应属性名 javaType 为所属类型--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">&quot;posts&quot;</span> <span class="attr">javaType</span>=<span class="string">&quot;Post&quot;</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--column 为数据库查到后取的别名 property 为javaType对象对应属性名--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;post_id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--因为数据库的字段与实体类属性名一致--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--所以在 mybatis-config.xml 配置 &lt;setting name=&quot;autoMappingBehavior&quot; value=&quot;FULL&quot;/&gt;--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--达到 自动映射行为 : 全部FULL 重复的 &lt;result/&gt; 可以省略--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--&lt;result column=&quot;&quot; property=&quot;&quot;/&gt;--&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="Post-职位实体类"><a href="#Post-职位实体类" class="headerlink" title="Post 职位实体类"></a>Post 职位实体类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.entity;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Post</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> String post_name;</span><br><span class="line">    <span class="keyword">private</span> List&lt;Emp&gt; emps = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;Emp&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">toString</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;Post&#123;&quot;</span> +</span><br><span class="line">                <span class="string">&quot;id=&quot;</span> + id +</span><br><span class="line">                <span class="string">&quot;, post_name=&#x27;&quot;</span> + post_name + <span class="string">&#x27;\&#x27;&#x27;</span> +</span><br><span class="line">                <span class="string">&quot;, emps=&quot;</span> + emps +</span><br><span class="line">                <span class="string">&#x27;&#125;&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> Integer <span class="title function_">getId</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setId</span><span class="params">(Integer id)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.id = id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getPost_name</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> post_name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setPost_name</span><span class="params">(String post_name)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.post_name = post_name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> List&lt;Emp&gt; <span class="title function_">getEmps</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> emps;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setEmps</span><span class="params">(List&lt;Emp&gt; emps)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.emps = emps;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="对应-Post-职位实体类-的实现接口-PostDao-接口类"><a href="#对应-Post-职位实体类-的实现接口-PostDao-接口类" class="headerlink" title="对应 Post 职位实体类 的实现接口 PostDao 接口类"></a>对应 Post 职位实体类 的实现接口 PostDao 接口类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.dao;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.entity.Post;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">PostDao</span> &#123;</span><br><span class="line">    List&lt;Post&gt; <span class="title function_">getAll</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="对应-Post-职位实体类-的映射配置文件-PostMapper-xml"><a href="#对应-Post-职位实体类-的映射配置文件-PostMapper-xml" class="headerlink" title="对应 Post 职位实体类 的映射配置文件 PostMapper.xml"></a>对应 Post 职位实体类 的映射配置文件 PostMapper.xml</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">mapper</span></span></span><br><span class="line"><span class="meta">        <span class="keyword">PUBLIC</span> <span class="string">&quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;</span></span></span><br><span class="line"><span class="meta">        <span class="string">&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!--namespace mapper接口 必填 随便填值 防止SQL语句ID重名--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">&quot;com.dao.PostDao&quot;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--resultType 返回类型 实体类全限定类名--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">&quot;getAll&quot;</span> <span class="attr">resultMap</span>=<span class="string">&quot;PostMapper&quot;</span>&gt;</span></span><br><span class="line">        SELECT * FROM post p</span><br><span class="line">        INNER JOIN emp_post ep ON ep.`post_id`=p.`id`</span><br><span class="line">        INNER JOIN emp e ON e.`id`=ep.`emp_id`</span><br><span class="line">        INNER JOIN depa d ON d.`id`=e.`depa_id`</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!--type 为resultMap返回类型--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">id</span>=<span class="string">&quot;PostMapper&quot;</span> <span class="attr">type</span>=<span class="string">&quot;Post&quot;</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--column 为数据库查到后取的别名 property 为type对象对应属性名--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;post_id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">&lt;!--因为数据库的字段与实体类属性名一致--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--所以在 mybatis-config.xml 配置 &lt;setting name=&quot;autoMappingBehavior&quot; value=&quot;FULL&quot;/&gt;--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--达到 自动映射行为 : 局部的PARTIAL 重复的 &lt;result/&gt; 可以省略--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--&lt;result column=&quot;&quot; property=&quot;&quot;/&gt;--&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">&lt;!--联合查询 一对一--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--property 为type对象对应属性名 javaType 为所属类型--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">&quot;emps&quot;</span> <span class="attr">javaType</span>=<span class="string">&quot;Emp&quot;</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--column 为数据库查到后取的别名 property 为javaType对象对应属性名--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;emp_id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--因为数据库的字段与实体类属性名一致--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--所以在 mybatis-config.xml 配置 &lt;setting name=&quot;autoMappingBehavior&quot; value=&quot;FULL&quot;/&gt;--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--达到 自动映射行为 : 全部FULL 重复的 &lt;result/&gt; 可以省略--&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--&lt;result column=&quot;&quot; property=&quot;&quot;/&gt;--&gt;</span></span><br><span class="line"></span><br><span class="line">            <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">&quot;depa_id&quot;</span> <span class="attr">javaType</span>=<span class="string">&quot;Depa&quot;</span>&gt;</span></span><br><span class="line">                <span class="comment">&lt;!--column 为数据库查到后取的别名 property 为javaType对象对应属性名--&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;depa_id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line">                <span class="comment">&lt;!--因为数据库的字段与实体类属性名一致--&gt;</span></span><br><span class="line">                <span class="comment">&lt;!--所以在 mybatis-config.xml 配置 &lt;setting name=&quot;autoMappingBehavior&quot; value=&quot;FULL&quot;/&gt;--&gt;</span></span><br><span class="line">                <span class="comment">&lt;!--达到 自动映射行为 : 全部FULL 重复的 &lt;result/&gt; 可以省略--&gt;</span></span><br><span class="line">                <span class="comment">&lt;!--&lt;result column=&quot;&quot; property=&quot;&quot;/&gt;--&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">association</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">association</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="mybatis-config-xml-MyBatis配置文件"><a href="#mybatis-config-xml-MyBatis配置文件" class="headerlink" title="mybatis-config.xml MyBatis配置文件"></a>mybatis-config.xml MyBatis配置文件</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">configuration</span></span></span><br><span class="line"><span class="meta">        <span class="keyword">PUBLIC</span> <span class="string">&quot;-//mybatis.org//DTD Config 3.0//EN&quot;</span></span></span><br><span class="line"><span class="meta">        <span class="string">&quot;http://mybatis.org/dtd/mybatis-3-config.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--可以配置在Java属性配置文件 *.properties 中--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">properties</span> <span class="attr">resource</span>=<span class="string">&quot;&quot;</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--可以配置键值对属性在这里而不用配置文件--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;&quot;</span> <span class="attr">value</span>=<span class="string">&quot;&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">settings</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 打印查询语句 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">&quot;logImpl&quot;</span> <span class="attr">value</span>=<span class="string">&quot;STDOUT_LOGGING&quot;</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--达到 自动映射行为 : 全部FULL 局部的PARTIAL 禁止自动匹配NONE--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">&quot;autoMappingBehavior&quot;</span> <span class="attr">value</span>=<span class="string">&quot;FULL&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">settings</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--为Java类型命名一个别名 alias 用于 mappers.xml 的 resultType 直接调用 不用写全限定类名--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">typeAliases</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--为一个Java类型命名一个别名--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--&lt;typeAlias type=&quot;&quot; alias=&quot;&quot;/&gt;--&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--为 com.entity 包 全部Java类型命名一个别名 别名为Java类名--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">package</span> <span class="attr">name</span>=<span class="string">&quot;com.entity&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">typeAliases</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--环境--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">environments</span> <span class="attr">default</span>=<span class="string">&quot;development&quot;</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--环境变量--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">environment</span> <span class="attr">id</span>=<span class="string">&quot;development&quot;</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--事务管理器--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">transactionManager</span> <span class="attr">type</span>=<span class="string">&quot;JDBC&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">transactionManager</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--数据源--&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">dataSource</span> <span class="attr">type</span>=<span class="string">&quot;POOLED&quot;</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span> <span class="attr">value</span>=<span class="string">&quot;root&quot;</span>/&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;password&quot;</span> <span class="attr">value</span>=<span class="string">&quot;simon&quot;</span>/&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;driver&quot;</span> <span class="attr">value</span>=<span class="string">&quot;com.mysql.jdbc.Driver&quot;</span>/&gt;</span></span><br><span class="line">                <span class="comment">&lt;!--MySQL数据库--&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;url&quot;</span> <span class="attr">value</span>=<span class="string">&quot;jdbc:mysql://localhost:3306/corp&quot;</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">dataSource</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">environment</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">environments</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--映射器--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mappers</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--实体类映射--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">mapper</span> <span class="attr">resource</span>=<span class="string">&quot;com/entity/DepaMapper.xml&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">mapper</span> <span class="attr">resource</span>=<span class="string">&quot;com/entity/EmpMapper.xml&quot;</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">mapper</span> <span class="attr">resource</span>=<span class="string">&quot;com/entity/PostMapper.xml&quot;</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">mappers</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="Test-测试类"><a href="#Test-测试类" class="headerlink" title="Test 测试类"></a>Test 测试类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.test;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.dao.DepaDao;</span><br><span class="line"><span class="keyword">import</span> com.dao.EmpDao;</span><br><span class="line"><span class="keyword">import</span> com.dao.PostDao;</span><br><span class="line"><span class="keyword">import</span> com.entity.Depa;</span><br><span class="line"><span class="keyword">import</span> com.entity.Emp;</span><br><span class="line"><span class="keyword">import</span> com.entity.Post;</span><br><span class="line"><span class="keyword">import</span> com.util.MybatisUtil;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.session.SqlSession;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.Arrays;</span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Test</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="type">SqlSession</span> <span class="variable">session</span> <span class="operator">=</span> MybatisUtil.getSession();</span><br><span class="line">        <span class="type">DepaDao</span> <span class="variable">depaDao</span> <span class="operator">=</span> session.getMapper(DepaDao.class);</span><br><span class="line">        <span class="type">EmpDao</span> <span class="variable">empDao</span> <span class="operator">=</span> session.getMapper(EmpDao.class);</span><br><span class="line">        <span class="type">PostDao</span> <span class="variable">postDao</span> <span class="operator">=</span> session.getMapper(PostDao.class);</span><br><span class="line"></span><br><span class="line">        List&lt;Depa&gt; depaDaoAll = depaDao.getAll();</span><br><span class="line">        <span class="keyword">for</span> (Depa depa : depaDaoAll) &#123;</span><br><span class="line">            System.out.println(depa);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        System.out.println(<span class="string">&quot;getByNames------三 || 四&quot;</span>);</span><br><span class="line">        List&lt;Emp&gt; byNames = empDao.getByNames(Arrays.asList(<span class="string">&quot;三&quot;</span>, <span class="string">&quot;四&quot;</span>));</span><br><span class="line">        <span class="keyword">for</span> (Emp emp : byNames) &#123;</span><br><span class="line">            System.out.println(emp);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        Map&lt;String, Object&gt; map = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;String, Object&gt;();</span><br><span class="line">        map.put(<span class="string">&quot;mapIdName&quot;</span>, <span class="number">2</span>);</span><br><span class="line">        map.put(<span class="string">&quot;mapNameList&quot;</span>, Arrays.asList(<span class="string">&quot;张三&quot;</span>, <span class="string">&quot;李四&quot;</span>, <span class="string">&quot;王五&quot;</span>));</span><br><span class="line">        List&lt;Emp&gt; byIdAndNames = empDao.getByIdAndNames(map);</span><br><span class="line">        System.out.println(<span class="string">&quot;byIdAndNames------&quot;</span> + map);</span><br><span class="line">        <span class="keyword">for</span> (Emp emp : byIdAndNames) &#123;</span><br><span class="line">            System.out.println(emp);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="type">Emp</span> <span class="variable">simon</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Emp</span>();</span><br><span class="line">        simon.setId(<span class="number">1</span>);</span><br><span class="line">        simon.setEmp_name(<span class="string">&quot;Simon&quot;</span>);</span><br><span class="line">        <span class="type">Depa</span> <span class="variable">depa</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Depa</span>();</span><br><span class="line">        depa.setId(<span class="number">1</span>);</span><br><span class="line">        simon.setDepa_id(depa);</span><br><span class="line">        <span class="keyword">if</span> (<span class="number">0</span> == empDao.saveOrUpdate(simon))</span><br><span class="line">            System.out.println(<span class="string">&quot;saveOrUpdate-----false&quot;</span>);</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            System.out.println(<span class="string">&quot;saveOrUpdate-----true&quot;</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="type">Integer</span> <span class="variable">del</span> <span class="operator">=</span> empDao.del(<span class="keyword">new</span> <span class="title class_">Integer</span>[]&#123;<span class="number">2</span>, <span class="number">3</span>&#125;);</span><br><span class="line">        <span class="keyword">if</span> (<span class="number">0</span> == del)</span><br><span class="line">            System.out.println(<span class="string">&quot;del-----false&quot;</span>);</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            System.out.println(<span class="string">&quot;del-----true&quot;</span>);</span><br><span class="line">        System.out.println(<span class="string">&quot;del-----&quot;</span> + del);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        List&lt;Emp&gt; empDaoAll = empDao.getAll();</span><br><span class="line">        <span class="keyword">for</span> (Emp emp : empDaoAll) &#123;</span><br><span class="line">            System.out.println(emp);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        List&lt;Post&gt; postDaoAll = postDao.getAll();</span><br><span class="line">        <span class="keyword">for</span> (Post post : postDaoAll) &#123;</span><br><span class="line">            System.out.println(post);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="控制台输出结果"><a href="#控制台输出结果" class="headerlink" title="控制台输出结果"></a>控制台输出结果</h2><p><code>mybatis-config.xml</code> 配置 <code>&lt;setting name=&quot;logImpl&quot; value=&quot;STDOUT_LOGGING&quot;/&gt;</code> 控制台会打印执行的SQL语句以及得到的参数</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line">==&gt;  Preparing: SELECT *,e.`id` eId,d.`id` dId FROM depa d INNER JOIN emp e ON d.`id`=e.`depa_id`</span><br><span class="line">==&gt; Parameters:</span><br><span class="line">&lt;==    Columns: id, depa_name, id, emp_name, depa_id, eId, dId</span><br><span class="line">&lt;==        Row: 1, 销售部, 2, 李四, 1, 2, 1</span><br><span class="line">&lt;==        Row: 1, 销售部, 3, 王五, 1, 3, 1</span><br><span class="line">&lt;==        Row: 1, 销售部, 4, 赵六, 1, 4, 1</span><br><span class="line">&lt;==        Row: 2, 美工部, 1, 张三, 2, 1, 2</span><br><span class="line">&lt;==      Total: 4</span><br><span class="line">Depa&#123;id=1, depa_name=&#x27;销售部&#x27;, emps=[Emp&#123;id=2, emp_name=&#x27;李四&#x27;, depa_id=null, posts=[]&#125;, Emp&#123;id=3, emp_name=&#x27;王五&#x27;, depa_id=null, posts=[]&#125;, Emp&#123;id=4, emp_name=&#x27;赵六&#x27;, depa_id=null, posts=[]&#125;]&#125;</span><br><span class="line">Depa&#123;id=2, depa_name=&#x27;美工部&#x27;, emps=[Emp&#123;id=1, emp_name=&#x27;张三&#x27;, depa_id=null, posts=[]&#125;]&#125;</span><br><span class="line">getByNames------三 || 四</span><br><span class="line">==&gt;  Preparing: SELECT * FROM emp e INNER JOIN depa d ON d.`id`=e.`depa_id` INNER JOIN emp_post ep ON ep.`emp_id`=e.`id` INNER JOIN post p ON p.`id`=ep.`post_id` WHERE e.`emp_name` LIKE CONCAT(&#x27;%&#x27;,?,&#x27;%&#x27;) OR e.`emp_name` LIKE CONCAT(&#x27;%&#x27;,?,&#x27;%&#x27;)</span><br><span class="line">==&gt; Parameters: 三(String), 四(String)</span><br><span class="line">&lt;==    Columns: id, emp_name, depa_id, id, depa_name, emp_id, post_id, id, post_name</span><br><span class="line">&lt;==        Row: 1, 张三, 2, 2, 美工部, 1, 1, 1, 职员</span><br><span class="line">&lt;==        Row: 2, 李四, 1, 1, 销售部, 2, 2, 2, 主管</span><br><span class="line">&lt;==        Row: 1, 张三, 2, 2, 美工部, 1, 4, 4, 部门经理</span><br><span class="line">&lt;==      Total: 3</span><br><span class="line">Emp&#123;id=1, emp_name=&#x27;张三&#x27;, depa_id=Depa&#123;id=2, depa_name=&#x27;美工部&#x27;, emps=[]&#125;, posts=[Post&#123;id=1, post_name=&#x27;职员&#x27;, emps=[]&#125;, Post&#123;id=4, post_name=&#x27;部门经理&#x27;, emps=[]&#125;]&#125;</span><br><span class="line">Emp&#123;id=2, emp_name=&#x27;李四&#x27;, depa_id=Depa&#123;id=1, depa_name=&#x27;销售部&#x27;, emps=[]&#125;, posts=[Post&#123;id=2, post_name=&#x27;主管&#x27;, emps=[]&#125;]&#125;</span><br><span class="line">==&gt;  Preparing: SELECT * FROM emp e INNER JOIN depa d ON d.`id`=e.`depa_id` INNER JOIN emp_post ep ON ep.`emp_id`=e.`id` INNER JOIN post p ON p.`id`=ep.`post_id` WHERE e.`id` = ? AND e.`emp_name` IN ( ? , ? , ? )</span><br><span class="line">==&gt; Parameters: 2(Integer), 张三(String), 李四(String), 王五(String)</span><br><span class="line">&lt;==    Columns: id, emp_name, depa_id, id, depa_name, emp_id, post_id, id, post_name</span><br><span class="line">&lt;==        Row: 2, 李四, 1, 1, 销售部, 2, 2, 2, 主管</span><br><span class="line">&lt;==      Total: 1</span><br><span class="line">byIdAndNames------&#123;mapIdName=2, mapNameList=[张三, 李四, 王五]&#125;</span><br><span class="line">Emp&#123;id=2, emp_name=&#x27;李四&#x27;, depa_id=Depa&#123;id=1, depa_name=&#x27;销售部&#x27;, emps=[]&#125;, posts=[Post&#123;id=2, post_name=&#x27;主管&#x27;, emps=[]&#125;]&#125;</span><br><span class="line">==&gt;  Preparing: UPDATE emp SET emp_name = ?, depa_id = ? where id = ?</span><br><span class="line">==&gt; Parameters: Simon(String), 1(Integer), 1(Integer)</span><br><span class="line">&lt;==    Updates: 1</span><br><span class="line">saveOrUpdate-----true</span><br><span class="line">==&gt;  Preparing: DELETE FROM emp WHERE id = ? OR id = ?</span><br><span class="line">==&gt; Parameters: 2(Integer), 3(Integer)</span><br><span class="line">&lt;==    Updates: 2</span><br><span class="line">del-----true</span><br><span class="line">del-----2</span><br><span class="line">==&gt;  Preparing: SELECT * FROM emp e INNER JOIN depa d ON d.`id`=e.`depa_id` INNER JOIN emp_post ep ON ep.`emp_id`=e.`id` INNER JOIN post p ON p.`id`=ep.`post_id`</span><br><span class="line">==&gt; Parameters:</span><br><span class="line">&lt;==    Columns: id, emp_name, depa_id, id, depa_name, emp_id, post_id, id, post_name</span><br><span class="line">&lt;==        Row: 1, Simon, 1, 1, 销售部, 1, 1, 1, 职员</span><br><span class="line">&lt;==        Row: 4, 赵六, 1, 1, 销售部, 4, 4, 4, 部门经理</span><br><span class="line">&lt;==        Row: 1, Simon, 1, 1, 销售部, 1, 4, 4, 部门经理</span><br><span class="line">&lt;==      Total: 3</span><br><span class="line">Emp&#123;id=1, emp_name=&#x27;Simon&#x27;, depa_id=Depa&#123;id=1, depa_name=&#x27;销售部&#x27;, emps=[]&#125;, posts=[Post&#123;id=1, post_name=&#x27;职员&#x27;, emps=[]&#125;, Post&#123;id=4, post_name=&#x27;部门经理&#x27;, emps=[]&#125;]&#125;</span><br><span class="line">Emp&#123;id=4, emp_name=&#x27;赵六&#x27;, depa_id=Depa&#123;id=1, depa_name=&#x27;销售部&#x27;, emps=[]&#125;, posts=[Post&#123;id=4, post_name=&#x27;部门经理&#x27;, emps=[]&#125;]&#125;</span><br><span class="line">==&gt;  Preparing: SELECT * FROM post p INNER JOIN emp_post ep ON ep.`post_id`=p.`id` INNER JOIN emp e ON e.`id`=ep.`emp_id` INNER JOIN depa d ON d.`id`=e.`depa_id`</span><br><span class="line">==&gt; Parameters:</span><br><span class="line">&lt;==    Columns: id, post_name, emp_id, post_id, id, emp_name, depa_id, id, depa_name</span><br><span class="line">&lt;==        Row: 1, 职员, 1, 1, 1, Simon, 1, 1, 销售部</span><br><span class="line">&lt;==        Row: 4, 部门经理, 4, 4, 4, 赵六, 1, 1, 销售部</span><br><span class="line">&lt;==        Row: 4, 部门经理, 1, 4, 1, Simon, 1, 1, 销售部</span><br><span class="line">&lt;==      Total: 3</span><br><span class="line">Post&#123;id=1, post_name=&#x27;职员&#x27;, emps=[Emp&#123;id=1, emp_name=&#x27;Simon&#x27;, depa_id=Depa&#123;id=1, depa_name=&#x27;销售部&#x27;, emps=[]&#125;, posts=[]&#125;]&#125;</span><br><span class="line">Post&#123;id=4, post_name=&#x27;部门经理&#x27;, emps=[Emp&#123;id=4, emp_name=&#x27;赵六&#x27;, depa_id=Depa&#123;id=1, depa_name=&#x27;销售部&#x27;, emps=[]&#125;, posts=[]&#125;, Emp&#123;id=1, emp_name=&#x27;Simon&#x27;, depa_id=Depa&#123;id=1, depa_name=&#x27;销售部&#x27;, emps=[]&#125;, posts=[]&#125;]&#125;</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechatpay.jpg" alt="Jaron Chim 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay.jpg" alt="Jaron Chim 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          <div class="post-tags">
              <a href="/tags/idea/" rel="tag"># idea</a>
              <a href="/tags/mysql/" rel="tag"># mysql</a>
              <a href="/tags/%E5%A4%9A%E5%AF%B9%E5%A4%9A/" rel="tag"># 多对多</a>
              <a href="/tags/%E4%B8%80%E5%AF%B9%E5%A4%9A/" rel="tag"># 一对多</a>
              <a href="/tags/%E5%A4%9A%E5%AF%B9%E4%B8%80/" rel="tag"># 多对一</a>
              <a href="/tags/mybatis/" rel="tag"># mybatis</a>
              <a href="/tags/%E4%B8%80%E5%AF%B9%E4%B8%80/" rel="tag"># 一对一</a>
              <a href="/tags/%E5%8A%A8%E6%80%81SQL/" rel="tag"># 动态SQL</a>
              <a href="/tags/%E6%98%A0%E5%B0%84%E9%85%8D%E7%BD%AE/" rel="tag"># 映射配置</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2018/04/03/MyBatis%E6%A1%86%E6%9E%B6%E6%98%A0%E5%B0%84%E6%96%87%E4%BB%B6%E9%85%8D%E7%BD%AE%E4%BB%A5%E5%8F%8A%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3/" rel="prev" title="MyBatis框架映射文件配置以及配置文件详解">
                  <i class="fa fa-angle-left"></i> MyBatis框架映射文件配置以及配置文件详解
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2018/04/24/%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F-%E9%A5%BF%E6%B1%89%E6%A8%A1%E5%BC%8F-%E6%87%92%E6%B1%89%E6%A8%A1%E5%BC%8F-%E7%A4%BA%E4%BE%8B/" rel="next" title="单例模式 饿汉模式 懒汉模式 示例">
                  单例模式 饿汉模式 懒汉模式 示例 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">粤ICP备2025405034号-1 </a>
  </div>
  <div class="copyright">
    &copy; 2016 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-user"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Jaron Chim</span>
  </div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>

</body>
</html>
